home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / dos / assignlock.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  134 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: assignlock.c,v 1.4 1996/10/24 15:50:24 aros Exp $
  4.     $Log: assignlock.c,v $
  5.     Revision 1.4  1996/10/24 15:50:24  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.3  1996/08/13 13:52:44  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced AROS_LA by AROS_LHA
  11.  
  12.     Revision 1.2  1996/08/01 17:40:47  digulla
  13.     Added standard header for all files
  14.  
  15.     Desc:
  16.     Lang: english
  17. */
  18. #include <exec/memory.h>
  19. #include <clib/exec_protos.h>
  20. #include <dos/filesystem.h>
  21. #include "dos_intern.h"
  22.  
  23. /*****************************************************************************
  24.  
  25.     NAME */
  26.     #include <clib/dos_protos.h>
  27.  
  28.     AROS_LH2(BOOL, AssignLock,
  29.  
  30. /*  SYNOPSIS */
  31.     AROS_LHA(STRPTR, name, D1),
  32.     AROS_LHA(BPTR,   lock, D2),
  33.  
  34. /*  LOCATION */
  35.     struct DosLibrary *, DOSBase, 102, Dos)
  36.  
  37. /*  FUNCTION
  38.     Create an assign from a given name to a lock. Replaces any older
  39.     assignments from that name, 0 cancels the assign completely. Do not
  40.     use or free the lock after calling this function - it becomes
  41.     the assign and will be freed by the system if the assign is removed.
  42.  
  43.     INPUTS
  44.     name - NUL terminated name of the assign.
  45.     lock - Lock to assigned directory.
  46.  
  47.     RESULT
  48.     !=0 success, 0 on failure. IoErr() gives additional information
  49.     in that case. The lock is freed on failure and must not be used
  50.     in that case too.
  51.  
  52.     NOTES
  53.  
  54.     EXAMPLE
  55.  
  56.     BUGS
  57.  
  58.     SEE ALSO
  59.  
  60.     INTERNALS
  61.  
  62.     HISTORY
  63.     29-10-95    digulla automatically created from
  64.                 dos_lib.fd and clib/dos_protos.h
  65.  
  66. *****************************************************************************/
  67. {
  68.     AROS_LIBFUNC_INIT
  69.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  70.  
  71.     BOOL success=1;
  72.     struct DosList *dl, *newdl=NULL;
  73.     struct Process *me=(struct Process *)FindTask(NULL);
  74.     struct IOFileSys io,*iofs=&io;
  75.     struct FileHandle *fh=(struct FileHandle *)BADDR(lock);
  76.  
  77.     if(lock)
  78.     {
  79.     newdl=MakeDosEntry(name,DLT_DIRECTORY);
  80.     if(newdl==NULL)
  81.     {
  82.         UnLock(lock);
  83.         me->pr_Result2=ERROR_NO_FREE_STORE;
  84.         return 0;
  85.     }else
  86.     {
  87.         newdl->dol_Unit  =fh->fh_Unit;
  88.         newdl->dol_Device=fh->fh_Device;
  89.         FreeDosObject(DOS_FILEHANDLE,fh);
  90.     }
  91.     }
  92.  
  93.     dl=LockDosList(LDF_DEVICES|LDF_ASSIGNS|LDF_WRITE);
  94.  
  95.     dl=FindDosEntry(dl,name,LDF_DEVICES|LDF_ASSIGNS);
  96.     if(dl==NULL)
  97.     {
  98.     if(newdl!=NULL)
  99.         AddDosEntry(newdl);
  100.     }else if(dl->dol_Type==DLT_DEVICE)
  101.     {
  102.     dl=newdl;
  103.     me->pr_Result2=ERROR_OBJECT_EXISTS;
  104.     success=0;
  105.     }else
  106.     {
  107.     RemDosEntry(dl);
  108.     if(newdl!=NULL)
  109.         AddDosEntry(newdl);
  110.     }
  111.  
  112.     if(dl!=NULL)
  113.     {
  114.     /* Prepare I/O request. */
  115.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  116.     iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  117.     iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  118.     iofs->IOFS.io_Device =dl->dol_Device;
  119.     iofs->IOFS.io_Unit   =dl->dol_Unit;
  120.     iofs->IOFS.io_Command=FSA_CLOSE;
  121.     iofs->IOFS.io_Flags  =0;
  122.  
  123.     /* Send the request. No errors possible. */
  124.     (void)DoIO(&iofs->IOFS);
  125.  
  126.     FreeDosEntry(dl);
  127.     }
  128.  
  129.     UnLockDosList(LDF_DEVICES|LDF_ASSIGNS|LDF_WRITE);
  130.  
  131.     return success;
  132.     AROS_LIBFUNC_EXIT
  133. } /* AssignLock */
  134.